<?php
 
session_start(); 

if (!isset($_SESSION['g_email'])) { 
	print
'

<html>
<head>
		<meta http-equiv="Content-Type" content="text/html"; charset="utf8">
		<link rel="shortcut icon" href="/images/cloud.png">
		<title>MLM - Бизнес портал</title>	
</head>
<body>
	<center>
	<table width="800">
			<tr>
				<td width=500 HEIGHT=27  valign=center style="background: #00C12B; margin: 5; padding: 10; font-family: tahoma;">
					<H2>MLM</H2>
				</td>
				<td width=300 HEIGHT=27  style="background: #00C12B; ">
					<form name = "login" action="index.php" method="post">
						<table width=200>
							<tr>
								<td style="font-size: 11px;  font-family: tahoma; padding: 3; margin: 1">Email</td>
								<td style="font-size: 11px;  font-family: tahoma; padding: 3; margin: 1 ">Пароль</td>
								</td>
								
							</tr>
							<tr>
								<td ><input type=text name=email size=20 style="font-size: 11px; margin: 1"></td>
								<td ><input type=password name=password size=15 style="font-size: 11px; margin: 1"></td>
								<td><input type=submit name=submit value=Вход style="font-size: 11px; margin: 1"></td>
							</tr>
							<tr>
								<td style="font-size: 11px;  font-family: tahoma; margin: 1;">
									<a href="register.php" style="pointer-events: none; cursor: default; margin: 1">регистрация</a>
								</td>
								<td style="font-size: 11px;  font-family: tahoma; margin: 1;">
									<a href="recoverypassword.php"  style="pointer-events: none; cursor: default; margin: 1">забыли пароль?</a>
								</td>
								</td></td>	
								
							</tr>
						</table>
					</form>
				</td>				
			</tr>	
			<tr>
				<table width=800 border=0>
					<tr>
						<td height=300 valign=top style="padding: 5; font-size: 11px;">
							<p style = "font-size: 11px; font-family: tahoma;">
								Управляйте своим бизнесом с любого места на Земле.
								<br>MLM это веб платформа для введения вашего бизнеса.
								<br><br><hr>
											<p style = "font-size: 11px; font-family: tahoma;">
											Возможности для Вас:
											<ul>
											<li style = "font-size: 11px; font-family: tahoma;">
												Единая база данных всех уровней партнеров.</li>			
											<li style = "font-size: 11px; font-family: tahoma;"> 
												Управление заказами. </li>
											<li style = "font-size: 11px; font-family: tahoma;"> 
												Древовидное представление партнеров.</li>
											<li style = "font-size: 11px; font-family: tahoma;"> 
												Автоматический подсчет результата.</li>
											<li style = "font-size: 11px; font-family: tahoma;"> 
												Гибкая система отчетности.</li>
											</ul>
							</p>											
							
							
						</td>
					<tr>
				</table>
			</tr>
			<tr>
				<table width=800 border=0>
					<tr><td>
							<center><hr>
									<a href="about.html" style = "font-size: 11px; font-family: tahoma; pointer-events: none; cursor: default; margin: 1">О нас </a>|
									<a href="contactus.html" style = "font-size: 11px; font-family: tahoma;pointer-events: none; cursor: default; margin: 1">Контакты </a>|
									<a href="term.html" style = "font-size: 11px; font-family: tahoma;pointer-events: none; cursor: default; margin: 1">Условия соглашения </a>|
									<a href="help.html" style = "font-size: 11px; font-family: tahoma;pointer-events: none; cursor: default; margin: 1">Помощь </a>
							</center>
					</td></tr>
				</table>				
			</tr>
	</table>
	<center>	
</body>
</html>

';

}
else
{
    header('Location: workflow.php');
    exit;
}
 
 //---------------------------------------------------------------
 if (!empty($_POST) && !isset($_SESSION['g_email']))
  {
    
    mysql_connect("localhost", "root", "555") or die (mysql_error());
    mysql_select_db("v_8074_mlm") or die (mysql_error());
   
    $email = $_POST['email'];
    $password = $_POST['password'];

    $query = "SELECT id, email, number, lastname, name, middlename, lastenterdt
          FROM users
          WHERE email= '".$email ."' and password = '".$password."'
          LIMIT 1";
          
    $sql = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_assoc($sql);


    if (mysql_num_rows($sql) == 1)
    {

        //session_register("user_id");
        //    $user_id= $row['id'];
            $_SESSION['userID'] = $row['id'];
        //session_register("email");
        //    $email= $row['email'];
            $_SESSION['g_email'] = $row['email'];
            $_SESSION['g_lastname'] = $row['lastname'];
            $_SESSION['g_name'] = $row['name'];
            $_SESSION['g_middlename'] = $row['middlename'];
            $_SESSION['g_number'] = $row['number'];
            
        header('Location: workflow.php');
        exit;
    }
    else;
    {
      die('<center>Ошибка: не верен email или пароль!</center>');
    }
}


?>
